<include file="Public/header" /> 

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4>模板列表</h4>
		<a href="<{:U('HomePageLayout/layout')}>" target="_blank" class="btn btn-default">添加新模板</a>
		<div class="bk10"></div>
		<table class="table table-bordered table-hover">
			<tr>
				<th>编号</th>
				<th>模板名称</th>
				<th>是否使用</th>
				<th>添加时间</th>
				<th>操作</th>
			</tr>
			
			<empty name="list">
				<tr>
					<td colspan="5" style="text-align:center;color:#999">～暂无数据～</td>
				</tr>
			<else /> 
			
				<foreach name="list" item="vo" key="k">
				
					<tr>
						<td><{$k+=1}></td>
						<td><{$vo['template_title']}></td>
						<td>
							<if condition="$vo['is_default'] eq 1">
								<a href="javascript:;">正在使用</a>
							</if>
						</td>
						<td><{$vo['createtime']|date="Y-m-d H:i:s",###}></td>
						<td>
							<a href="<{:U('HomePageLayout/layout',array('id'=>$vo['homepage_id']))}>" target="_blank">编辑</a>
							<if condition="$vo['is_default'] eq 0">
								<a href="javascript:;" onclick="change_homepage(<{$vo['homepage_id']}>,<{$vo['merchant_id']}>)">使用</a>
							</if>
							<a href="<{:U('HomePageLayout/preview',array('id'=>$vo['homepage_id']))}>" target="_blank">预览</a>
						</td>
					</tr>
				</foreach>
			
			</empty> 
			
		</table>
		
	</div>
	<!-- mainCon// -->
	
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
	var is_update = <{$list[0]['is_update']}>;
	if(is_update == 0){
		console.debug('不更新')
	}else{
		console.debug('需要更新')
	}
	function change_homepage(homepage_id,merchant_id){
		layer.confirm('您是否确认更换模板?', {icon: 3, title:'提示'}, function(index){
			
			$.post(
				"<{:U('HomePageList/ChangeHomePage')}>",
				{"homepage_id":homepage_id,"merchant_id":merchant_id},
				function(r){
					layer.close(index);
					if(r.status == 1){
						layer.close(index);
						layer.alert(r.msg,{icon: 2});
						return false;
					}else{
						layer.msg(r.msg);
						setTimeout(function(){window.location.reload();},1000);
						return false;
					}
				}
			);
		});
	}

</script>

<include file="Public/footer" /> 